<?php
namespace app\home\controller;
use app\common\controller\Table;
use think\Controller;

//表格控制器继承
Class Test extends Table {

    protected $table_header = [
        ['key'=>'id','name'=>'编码','search'=>0],
        ['key'=>'name','name'=>'名称','search'=>1],
        ['key'=>'update_time','name'=>'更新时间','search'=>0],
        ['key'=>'create_time','name'=>'创建时间','search'=>0],
        ['key'=>'is_show','name'=>'switch测试','templet'=>"switchTpl(d,'is_show')",'search'=>0],
        ['key'=>'url','name'=>'复制测试','search'=>0],
    ];
    protected $excel_key = ['编码','名称','是否删除','权值','更新时间','创建时间'];
    //excel处理
    public function excelUrl($key=[],$return_data=0){
        parent::excelUrl($this->excel_key,0);
    }

    public function data($page=1,$limit=10){
        parent::data($page,$limit);
        $res = $this->data;
        //可对数据整合打包发给前端
        if($res['code']==0){
            $excel = $this->excelList('common','测试名',
                '测试文件名',$this->count,3000,$this->where);
            $res['excel'] = $excel;
        }
        foreach ($res['data'] as $k=>$v){
            $dom = "<button class='layui-btn layui-btn-xs copy-btn'
                data-clipboard-text='复制内容' >复制</button>";
            $res['data'][$k]['url'] = $dom;
        }
        return json($res);//已经是结果 ajax
    }

    public function index(){
        parent::index();
        $table_pri =$this->privilege;
        $table_pri['read'] = 0;
        $this->assign([
            'table_header'=>$this->table_header,
            'pri'=>$table_pri
        ]);
        return $this->fetch();
    }


    public function detail(){
        parent::detail();
        //iframe 跳转到该页面
        return $this->fetch();
    }

    public function edit(){
        parent::edit();
        //iframe 跳转到该页面
        return $this->fetch();
    }

    public function add(){
        parent::add();
        //iframe 跳转到该页面
        return $this->fetch();
    }

    public function recycleData($page=1,$limit=15){
        parent::recycleData($page,$limit);
        $res = $this->data;
        if($res['code']==0){
            $excel = $this->excelList('recycle','测试名',
                '测试文件名',$this->count,3000,$this->where);
            $res['excel'] = $excel;
        }
        return json( $res );
    }

    public function recycleindex()
    {
        parent::recycleindex();
        $pri = $this->privilege;
        $this->assign([
            'pri'=>$pri,
            'table_header'=> $this->table_header
        ]);
        return $this->fetch();
    }

}